package com.liuyucheng.concurrent.callable;

import java.util.concurrent.*;

public class SimpleCallableExample {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 创建Callable任务
        Callable<String> task = () -> {
            Thread.sleep(1000);
            return "Hello from Callable!";
        };

        // 使用FutureTask包装Callable
        FutureTask<String> futureTask = new FutureTask<>(task);

        // 启动线程
        new Thread(futureTask).start();

        // 获取结果（阻塞主线程）
        System.out.println(futureTask.get());
    }
}